﻿' NOTE: You can use the "Rename" command on the context menu to change the class name "Service1" in code, svc and config file together.
' NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.vb at the Solution Explorer and start debugging.
Public Class Service1
    Implements IServiceManagement



    Public Sub New()

    End Sub

    Shared ServerName As String

    Public Function GetData(ByVal value As Integer) As String Implements IServiceManagement.GetData
        Return String.Format("You entered: {0}", value)
    End Function

    Public Function GetDataUsingDataContract(ByVal composite As CompositeType) As CompositeType Implements IServiceManagement.GetDataUsingDataContract
        If composite Is Nothing Then
            Throw New ArgumentNullException("composite")
        End If
        If composite.BoolValue Then
            composite.StringValue &= "Suffix"
        End If
        Return composite
    End Function

    Public Function GetServerHealth(ByVal ServerName As String) As String Implements IServiceManagement.GetServerHealth
        Dim objMonitor As New Monitor("eraweb1")
        Dim ServerHealth As String
        ServerHealth = ("Needs Attention :" + objMonitor.CheckAttenion)
        objMonitor = Nothing
        Return ServerHealth
    End Function

    Public Function GetCounters(ServerName As String, Username As String, Password As String) As List(Of String) Implements IServiceManagement.GetCounters
        Dim counters = New List(Of String)
        Dim objMonitor As New Monitor(ServerName)
        For i As Integer = 1 To 6
            'Hard coded Username and Password to access performance counters for specfic server. 
            counters.Add(objMonitor.PerformanceMonitor(Username, Password, i))

            If (i = 7) Then
                Exit For

            End If
        Next
        Return counters
    End Function

    Public Function GetServerStatus(FullComputername As String) As String Implements IServiceManagement.GetServerStatus
        Dim objMonitor As New Monitor(ServerName)
        Dim SSTATVALUE As String
        SSTATVALUE = ("Status of Server: " + objMonitor.CheckPool)

        Return SSTATVALUE
    End Function

    Public Function ResetIIS(ServerName As String) As Boolean Implements IServiceManagement.ResetIIS
        Dim objMonitor As New Monitor(ServerName)
        Dim Value
        Value = objMonitor.IISReset()
        Return Value
    End Function

    Public Function ServerOnline(ServerName As String) As String Implements IServiceManagement.ServerOnline
        Dim objMonitor As New Monitor(ServerName)
        Dim Value As String

        Value = objMonitor.ServerOnline()
        Return Value

    End Function

    Public Function ServerOffline(ServerName As String) As Boolean Implements IServiceManagement.ServerOffline
        Dim objMonitor As New Monitor(ServerName)
        Dim Value
        Value = objMonitor.ServerOffline()
        objMonitor = Nothing

        Return Value
    End Function

    Function ServerNamesList() As List(Of String) Implements IServiceManagement.ServerNamesList
        Dim objMonitor As New Monitor(ServerName)
        Dim ServerList As List(Of String)

        ServerList = objMonitor.SerNames()
        Return ServerList
    End Function


End Class
